package com.demo.study.thread.self;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author baymax
 * @since 2025-07-04
 */
public class DemoClient {
    public static void main(String[] args) throws InterruptedException {
        selfTest();
        //javaTest();
    }

    private static void selfTest() {
        SelfThreadPool threadPool = new SelfThreadPool(2, 4, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>(4),
            new RejectHandler.DiscardHandler());
        for (int i = 0; i < 10; i++) {
            threadPool.execute(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("threadPool execute " + Thread.currentThread().getName());
            });
        }
        System.out.println("main thread");
        threadPool.join();
    }

    private static void javaTest() {
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2, 4, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>(2));
        for (int i = 0; i < 7; i++) {
            threadPool.execute(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("threadPool execute " + Thread.currentThread().getName());
            });
        }
        System.out.println("main thread");
    }

}
